#============================================================================================================================================================================================#
##Main Replication Files for "Counterinsurgency Tactics, Rebel Grievances, and Who Keeps Fighting"
rm(list=ls())

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#loading packages
ipak <- function(pkg){  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("stargazer") 
ipak(packages)

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
##Reading in the Data
#setwd("")
data <- read.csv("MasterData.csv")

#============================================================================================================================================================================================#
#============================================================Table 3=========================================================================================================================#
#============================================================================================================================================================================================#
##MODEL 1
lm.fight.intern.org.ind <- lm(War_Independence_All_Claim ~ Interned + citizen_army, data=data)
summary(lm.fight.intern.org.ind)

##MODEL 2
lm.fight.intern.org.ind.all.vars <- lm(War_Independence_All_Claim ~ Interned + citizen_army + rank_file + age + left_early + early_join + factor(easter_rising_location_endplace), data=data)
summary(lm.fight.intern.org.ind.all.vars)
summary(lm.fight.intern.org.ind.all.vars)$coefficients[2,] ##Interned
summary(lm.fight.intern.org.ind.all.vars)$coefficients[3,] ##citizen_army
summary(lm.fight.intern.org.ind.all.vars)$coefficients[4,] ##rank_file
summary(lm.fight.intern.org.ind.all.vars)$coefficients[5,] ##age
summary(lm.fight.intern.org.ind.all.vars)$coefficients[6,] ##left_early
summary(lm.fight.intern.org.ind.all.vars)$coefficients[7,] ##early_join
summary(lm.fight.intern.org.ind.all.vars)$coefficients[1,] ##constant

##MODEL 3
lm.count <- lm(War_Independence_Count ~ Interned + citizen_army, data=data)
summary(lm.count)

##MODEL 4
lm.count.all <- lm(War_Independence_Count ~ Interned + citizen_army + rank_file + age + left_early + early_join + factor(easter_rising_location_endplace), data=data)
summary(lm.count.all)
summary(lm.count.all)$coefficients[2,] ##Interned
summary(lm.count.all)$coefficients[3,] ##citizen_army
summary(lm.count.all)$coefficients[4,] ##rank_file
summary(lm.count.all)$coefficients[5,] ##age
summary(lm.count.all)$coefficients[6,] ##left_early
summary(lm.count.all)$coefficients[7,] ##early_join
summary(lm.count.all)$coefficients[1,] ##constant

##Results
stargazer(lm.fight.intern.org.ind, lm.fight.intern.org.ind.all.vars, omit = c("easter_rising_location_endplace"))

stargazer(lm.count, lm.count.all, omit = c("easter_rising_location_endplace"))


#============================================================================================================================================================================================#
#============================================================Descriptive Statistics for Internment===========================================================================================#
#============================================================================================================================================================================================#
sum(data$Interned) ##1162 individuals interned
sum(!data$Interned) ##608 individuals not interned
